package ctype

import "github.com/goccy/go-json"

//type UserStatus string
//
//const (
//	Man     UserStatus = "nan"     // 男
//	unknown UserStatus = "unknown" // 位置
//	woman   UserStatus = "woman"   // 女
//)
//
//func (s *UserStatus) Scan(value interface{}) error {
//	strValue, ok := value.(string)
//	if !ok {
//		return errors.New("failed to scan UserStatus")
//	}
//	*s = UserStatus(strValue)
//	return nil
//}
//
//func (s UserStatus) Value() (driver.Value, error) {
//	return string(s), nil
//}

type SexStatus int

const (
	Unknown SexStatus = iota
	Man
	Woman
)

func (s SexStatus) MarshalJSON() ([]byte, error) {
	return json.Marshal(s.String())
}

func (s *SexStatus) UnmarshalJSON(data []byte) error {
	var str string
	if err := json.Unmarshal(data, &str); err != nil {
		return err
	}
	switch str {
	case "男":
		*s = Man
	case "女":
		*s = Woman
	default:
		*s = Unknown
	}
	return nil
}

func (s SexStatus) String() string {
	switch s {
	case Man:
		return "男"
	case Woman:
		return "女"
	default:
		return "保密"
	}
}
